<template>
  <div class="newsinfo-container">
    <!--    大标题-->
    <h1 class="title">{{ newsInfoList.title }}</h1>
    <!--    子标题-->
    <p class="newsinfo-nav">
      <span>发表时间：{{ newsInfoList.add_time | dateFormat }}</span>
      <span>点击： {{ newsInfoList.click }}次</span>
    </p>
    <hr>
    <!--    内容区域-->
    <div class="content" v-html="newsInfoList.content"></div>
  </div>
</template>

<script>
export default {
  name: 'NewsInfo',
  data () {
    return {
      newsInfoList: {},
      id: this.$route.params.id
    }
  },
  created () {
    this.getNewsInfo()
  },
  methods: {
    getNewsInfo () {
      // 获取新闻详情数据
      this.$http.get('news/show', { params: { id: this.id } }).then(res => {
        // 状态 0:成功， 1:失败
        if (res.data.status === 0) {
          this.newsInfoList = res.data.message[0]
        } else {
          this.$toast('加载失败')
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.newsinfo-container {
  padding: 0 5px;

  .title {
    font-size: 16px;
    text-align: center;
    margin: 10px 0;
    color: orangered;
  }

  .newsinfo-nav {
    display: flex;
    justify-content: space-between;
    color: #26a2ff;
  }

  .content {
    img {
      width: 100%;
    }
  }
}
</style>
